package com.common.service;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix ="system")
public class SystemConfigService {

	@Autowired
	private Environment environment;
	
	private String version;
	
	private String appId;
	
	private String orgId;
	
	private String ipAddress;

	public void setVersion(String version) {
		this.version = version;
	}

	public void setAppId(String appId) {
		this.appId = appId;
	}

	public void setOrgId(String orgId) {
		this.orgId = orgId;
	}

	public void setIpAddress(String ipAddress) {
		this.ipAddress = ipAddress;
	}

	
	public String getVersion() {
		return version;
	}

	public String getAppId() {
		return appId;
	}

	public String getOrgId() {
		return orgId;
	}

	public String getIpAddress() {
		if(ipAddress==null) {
			try {
				ipAddress=InetAddress.getLocalHost().getHostAddress();
			} catch (UnknownHostException e) {
				e.printStackTrace();
			}
		}
		return ipAddress;
	}
	
	public String getProptity(String key) {
		return environment.getProperty(key);
	}
	
	public String getProptity(String key,String defaultValue) {
		return environment.getProperty(key, defaultValue);
	}
}
